package com.itzzj.common.utils;

import io.minio.BucketExistsArgs;
import io.minio.MakeBucketArgs;
import io.minio.MinioClient;
import io.minio.messages.Bucket;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class MinIOUtil {

    @Autowired
    private MinioClient minioClient;

    /**
     * 创建 桶
     * @param bucket
     * @throws Exception
     */
    public void createBucket(String bucket) throws Exception {
        boolean flag = minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucket).build());
        if(!flag){
            minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucket).build());
        }
    }

    /**
     * 列出所有存储 桶
     * @return
     */
    public List<Bucket> listBuckets() throws Exception{
        return minioClient.listBuckets();
    }

}
































